const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const PermissionSchema = new Schema({
  parentId: {
    type: Schema.Types.ObjectId,
    ref: 'Permission',
    default: null
  },
  type: {
    type: String,
    enum: ['目录', '菜单', '按钮'],
    required: true
  },
  name: {
    type: String,
    required: true
  },
  displayOrder: {
    type: Number,
    default: 0
  },
  code: {
    type: String,
    required: true,
    unique: true
  },
  path: {
    type: String
  },
  displayStatus: {
    type: String,
    enum: ['显示', '隐藏'],
    default: '显示'
  },
  status: {
    type: String,
    enum: ['正常', '停用'],
    default: '正常'
  }
});

module.exports = mongoose.model('Permission', PermissionSchema);